﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Windows.Media.Imaging;
using ScoringClient.Notification;

namespace ScoringClient.ViewModels
{
    class LoginViewModel : ViewModelBase
    {
        private const int MAX_ATTEMPT = 2;
        private const int USERNAME_LENGTH = 30;
        private const int PASSWORD_LENGTH = 80;
        private int attemptCount = 0;

        #region Username
        private string username;
        public string Username
        {
            get
            {
                return username;
            }
            set
            {
                if (value == username) return;
                username = value;
                OnPropertyChanged("Username");
            }
        }
        #endregion

        #region UsernameLength
        public int UsernameLength
        {
            get
            {
                return USERNAME_LENGTH;
            }
        }
        #endregion

        #region Password
        private string password;
        public string Password
        {
            get
            {
                return password;
            }
            set
            {
                if (value == password) return;
                password = value;
                OnPropertyChanged("Password");
            }
        }
        #endregion

        #region PasswordLength
        public int PasswordLength
        {
            get
            {
                return PASSWORD_LENGTH;
            }
        }

        #endregion

        public bool IsMutipleWrongAttempt
        {
            get
            {
                return attemptCount >= MAX_ATTEMPT;
            }
        }

        internal LoginViewModel()
        {
            this.WindowTitle = "人工阅卷客户端-登录";
            this.WindowWidth = 1000;
            this.WindowHeight = 620;
        }

        public void Login()
        {
            attemptCount++;

            NotificationRequest scoringCatalogRequest = NotificationManager.Instance.CreateRequest(NotificationAction.ScoringCatalog);
            NotificationManager.Instance.MoveOn(scoringCatalogRequest);

            attemptCount = 0;
        }
    }
}
